<?php

require_once('lib/Schedule.php');
require_once('lib/Util.php');
require_once('lib/MixiAppliAPI.php');

$api = new MixiAppliAPI(array_merge($_GET, $_POST));

$api->validate_params(array(
    'start_date' => array('not_blank', 'date'),
    'start_time' => array('time'),
    'end_date'   => array('not_blank', 'date'),
    'end_time'   => array('time'),
    'flag'       => array(array('in_array',
        SCHEDULE_ALL,
        SCHEDULE_DAY,
        SCHEDULE_NIGHT,
    )),
));

$schedule = new Schedule();
$schedule->member_id  = $api->viewer_id;
$schedule->start_date = $api->params['start_date'];
$schedule->end_date   = $api->params['end_date'];
$schedule->flag       = $api->params['flag'];

if (isset($api->params['start_time']))
    $schedule->start_time = $api->params['start_time'];
if (isset($api->params['end_time']))
    $schedule->end_time   = $api->params['end_time'];

if (!$schedule->insert())
    $api->set_error('could not insert schedule');

$api->set_result($schedule);

?>
